package com.share.quartz.service;


import org.apache.log4j.Logger;
import org.quartz.Job;

import com.share.quartz.service.IQuartzJobEntity;
import com.share.quartz.service.QuartzJobBean;

public class QuartzJobEntity implements IQuartzJobEntity {


	private static final long serialVersionUID = -1982327785453002088L;
	private Logger logger = Logger.getLogger(getClass());
	private String id;
	//需和配置文件中bean的id保持一致 
	private String jobName;
	private String groupName;
	private String clazzName;
	private String cronExpression;
	private String cronMethod;

	public QuartzJobEntity() {
		super();
		this.cronMethod = "execute";
	}

	public QuartzJobEntity(String jobName, String groupName, String clazzName,
			String cronExpression,String cronMethod) {
		setJobName(jobName);
		setGroupName(groupName);
		setClazzName(clazzName);
		setCronExpression(cronExpression);
		setCronMethod(cronMethod);
		logger.info(this.toString());
	}

	/**
	 * @return the cronMethod
	 */
	public String getCronMethod() {
		return cronMethod;
	}

	/**
	 * @param cronMethod the cronMethod to set
	 */
	public void setCronMethod(String cronMethod) {
		if(cronMethod!=null&&!"".equals(cronMethod)){
			this.cronMethod = cronMethod;
		}else{
			this.cronMethod = "execute";
		}
		
	}
	@Override
	public String toString() {
		return getJobName()+"+"+getGroupName()+"+"+getClazzName()+"+"+getCronMethod()+"+"+getCronExpression();
	}
	public String getTriggerName() {
		return this.getJobName() + "Trigger";
	}

	/**
	 * 根据类名返回类class
	 * 
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	public Class<? extends Job> getClazz() throws InstantiationException,
			IllegalAccessException, ClassNotFoundException {
		logger.info("调度的class为-----" + getClazzName());
		if (getClazzName() != null && !"".equals(getClazzName())) {
			return ((QuartzJobBean) Class.forName(this.getClazzName()).newInstance())
					.getClass();
		} else {
			return QuartzJobBean.class;
		}
	}
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * @return the jobName
	 */
	public String getJobName() {
		return jobName;
	}

	/**
	 * @param jobName
	 *            the jobName to set
	 */
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}

	/**
	 * @return the groupName
	 */
	public String getGroupName() {
		return groupName;
	}

	/**
	 * @param groupName
	 *            the groupName to set
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	/**
	 * @return the clazzName
	 */
	public String getClazzName() {
		return clazzName;
	}

	/**
	 * @param clazzName
	 *            the clazzName to set
	 */
	public void setClazzName(String clazzName) {
		this.clazzName = clazzName;
	}

	/**
	 * @return the cronExpression
	 */
	public String getCronExpression() {
		return cronExpression;
	}

	/**
	 * @param cronExpression
	 *            the cronExpression to set
	 */
	public void setCronExpression(String cronExpression) {
		this.cronExpression = cronExpression;
	}

}
